﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;

public class WebSiteMainConfiguration: ConfigurationSection
{   
    public static WebSiteMainConfiguration GetConfig()
    {
        return ConfigurationManager.GetSection("MiWebSiteConfiguration/MainConfiguration") as WebSiteMainConfiguration;
    }

    [ConfigurationProperty("Settings")]
    public SettingElementCollection Settings
    {
        get
        {
            return this["Settings"] as SettingElementCollection;
        }
    }

    [ConfigurationProperty("Connections")]
    public ConnectionStringCollection Connections
    {
        get
        {
            return this["Connections"] as ConnectionStringCollection;
        }
    }

    [ConfigurationProperty("MailConfig")]
    public MailConfigCollection MailConfig
    {
        get
        {
            return this["MailConfig"] as MailConfigCollection;
        }
    }
}

public class SettingElement : ConfigurationElement
{
    [ConfigurationProperty("name", IsRequired = false)]
    public String name
    {
        get
        {
            return (String)this["name"];
        }
        set
        {
            this["name"] = value;
        }
    }

    [ConfigurationProperty("value", IsRequired = false)]
    public String value
    {
        get
        {
            return (String)this["value"];
        }
        set
        {
            this["value"] = value;
        }
    }

}

public class SettingElementCollection : ConfigurationElementCollection
{
    public SettingElement this[int index]
    {
        get
        {
            return base.BaseGet(index) as SettingElement;
        }
        set
        {
            if (base.BaseGet(index) != null)
            {
                base.BaseRemoveAt(index);
            }
            this.BaseAdd(index, value);
        }
    }

    public SettingElement this[string name]
    {
        get
        {
            return BaseGet(name) as SettingElement;
        }
        set
        {

        }
    }

    protected override ConfigurationElement CreateNewElement()
    {
        return new SettingElement();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
        return ((SettingElement)element).name;
    }
}

public class ConnectionStringCollection : ConfigurationElementCollection
{
    public SettingElement this[int index]
    {
        get
        {
            return base.BaseGet(index) as SettingElement;
        }
        set
        {
            if (base.BaseGet(index) != null)
            {
                base.BaseRemoveAt(index);
            }
            this.BaseAdd(index, value);
        }
    }

    public SettingElement this[string name]
    {
        get
        {
            return BaseGet(name) as SettingElement;
        }
        set
        {

        }
    }

    protected override ConfigurationElement CreateNewElement()
    {
        return new SettingElement();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
        return ((SettingElement)element).name;
    }
}

public class MailConfigCollection : ConfigurationElementCollection
{
    public SettingElement this[int index]
    {
        get
        {
            return base.BaseGet(index) as SettingElement;
        }
        set
        {
            if (base.BaseGet(index) != null)
            {
                base.BaseRemoveAt(index);
            }
            this.BaseAdd(index, value);
        }
    }

    public SettingElement this[string name]
    {
        get
        {
            return BaseGet(name) as SettingElement;
        }
        set
        {

        }
    }

    protected override ConfigurationElement CreateNewElement()
    {
        return new SettingElement();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
        return ((SettingElement)element).name;
    }
}

public class MWSModuleConfiguration : ConfigurationSection
{
    /// <summary>
    /// Returns an ASPNET2Configuration instance
    /// </summary>
    public static MWSModuleConfiguration GetConfig(string configPath)
    {
        return ConfigurationManager.GetSection(configPath) as MWSModuleConfiguration;
    }


    [ConfigurationProperty("rootURL", DefaultValue = "/", IsRequired = false)]
    public string rootURL
    {
        get
        {
            return this["rootURL"] as string;
        }
    }

    [ConfigurationProperty("adminURL", IsRequired = true)]
    public string adminURL
    {
        get
        {
            return this["adminURL"] as string;
        }
    }

    [ConfigurationProperty("skins")]
    public ModuleSkinCollection skins
    {
        get
        {
            return this["skins"] as ModuleSkinCollection;
        }
    }
    [ConfigurationProperty("counts")]
    public ModuleItemCountCollection counts
    {
        get
        {
            return this["counts"] as ModuleItemCountCollection;
        }
    }
}

/// <summary>
/// Summary description for ASPNET2ConfigurationStateCollection
/// </summary>
public class ModuleSkinCollection : ConfigurationElementCollection
{
    public SettingElement this[int index]
    {
        get
        {
            return base.BaseGet(index) as SettingElement;
        }
        set
        {
            if (base.BaseGet(index) != null)
            {
                base.BaseRemoveAt(index);
            }
            this.BaseAdd(index, value);
        }
    }

    public SettingElement this[string skinName]
    {
        get
        {
            return BaseGet(skinName) as SettingElement;
        }
        set
        {
            
        }
    }

    protected override ConfigurationElement CreateNewElement()
    {
        return new SettingElement();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
        return ((SettingElement)element).name;
    }
}

/// <summary>
/// Summary description for ASPNET2ConfigurationStateCollection
/// </summary>
public class ModuleItemCountCollection : ConfigurationElementCollection
{
    public SettingElement this[int index]
    {
        get
        {
            return base.BaseGet(index) as SettingElement;
        }
        set
        {
            if (base.BaseGet(index) != null)
            {
                base.BaseRemoveAt(index);
            }
            this.BaseAdd(index, value);
        }
    }

    public SettingElement this[string itemName]
    {
        get
        {
            return BaseGet(itemName) as SettingElement;
        }
        set
        {

        }
    }

    protected override ConfigurationElement CreateNewElement()
    {
        return new SettingElement();
    }

    protected override object GetElementKey(ConfigurationElement element)
    {
        return ((SettingElement)element).name;
    }
}
